package com.coin900.coin.service.fu;

import com.coin900.coin.persist.fu.FuUserWalletVO;
import com.value.mybatis.IDaoRouter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FuUserWalletService implements IFuUserWalletService {

    @Override
    public List<FuUserWalletVO> loadFuUserWallet(Map<String, Object> params) {
        return this.daoRouter.query("FuUserWallet.loadFuUserWallet", params);
    }

    @Override
    public List<FuUserWalletVO> loadTotalWallet(Map<String, Object> params) {
        return this.daoRouter.query("FuUserWallet.loadTotalWallet", params);
    }

    @Override
    public FuUserWalletVO getUserWallet(Long userId, Long coinId) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("coinId", coinId);
        params.put("dataStatus", 1);
        return this.daoRouter.queryForObject("FuUserWallet.loadFuUserWallet", params);
    }

    @Override
    public void insertFuUserWallet(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.insert("FuUserWallet.insertFuUserWallet", fuUserWalletVO);
    }

    @Override
    public void updateFuUserWallet(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.updateFuUserWallet", fuUserWalletVO);
    }

    @Override
    public void doPayForTheOrder(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.doPayForTheOrder", fuUserWalletVO);
    }

    @Override
    public void doIncreaseBlocked(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.doIncreaseBlocked", fuUserWalletVO);
    }

    @Override
    public void deleteFuUserWallet(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.deleteFuUserWallet", fuUserWalletVO);
    }

    @Override
    public void doRechargeSuccess(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.doRechargeSuccess", fuUserWalletVO);
    }

    @Override
    public void doWithdrawFail(FuUserWalletVO fuUserWalletVO) {
        // 0 - 扣除 blocked，增加 balance，增加 avçailable
        this.daoRouter.update("FuUserWallet.doWithdrawFail", fuUserWalletVO);
    }

    @Override
    public void doWithdrawPayed(FuUserWalletVO fuUserWalletVO) {
        // 3 - 扣除 blocked
        this.doWallectUnBlock(fuUserWalletVO);
    }

    @Override
    public void doIncreaseTokenBalance(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.updateFuUserWallet", fuUserWalletVO);
    }

    @Override
    public void doWallectUnBlock(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.doWallectUnBlock", fuUserWalletVO);
    }

    @Override
    public void doWallectBlock(FuUserWalletVO fuUserWalletVO) {
        this.daoRouter.update("FuUserWallet.doWallectBlock", fuUserWalletVO);
    }

    @Autowired
    private IDaoRouter daoRouter;

}